#include "ByteConverterDialog.h"
ByteConverterDialog::ByteConverterDialog(QWidget * parent): QDialog(parent)
{
   setupUi(this);
   connect(decEdit, SIGNAL(textChanged(const QString &)), this, SLOT(decChanged(const QString &)));
   connect(hexEdit, SIGNAL(textChanged(const QString &)), this, SLOT(hexChanged(const QString &)));
   connect(binEdit, SIGNAL(textChanged(const QString &)), this, SLOT(binChanged(const QString &)));
}
void ByteConverterDialog::changeValue(int i)
{
   if (value != i) {
      value = i;
      hexEdit->setText(QString::number(i,16));
      decEdit->setText(QString::number(i,10));
      binEdit->setText(QString::number(i,2));
   }
}
void ByteConverterDialog::decChanged(const QString& text)
{
   bool ok = false;
   int i = text.toInt(&ok, 10);
   if(ok)changeValue(i);
}
void ByteConverterDialog::hexChanged(const QString& text)
{
   bool ok = false;
   int i = text.toInt(&ok, 16);
   if(ok)changeValue(i);
}
void ByteConverterDialog::binChanged(const QString& text)
{
   bool ok = false;
   int i = text.toInt(&ok, 2);
   if(ok)changeValue(i);
}